Ext.define('channel.commodity.CommoditySnapWin',{
	_winType : 'exclude',
	closeAction : 'hide',
	extend : 'Ext.window.Window',
	width : 500,
	resizable : false,
	modal : true,	
	initComponent : function(){
		this.form = Ext.create('Ext.form.Panel',{
			border : false,		
			bodyPadding: 5,
			defaults : {labelAlign : 'right',anchor:'90%',xtype:'textfield'},
			items :[
				{
			        fieldLabel: '商品编号',
			        name: 'commodity',
			        xtype : 'numberfield',
			        maxLenght : 50,
			        allowBlank: false
			    },
			    {
					fieldLabel:'渠道',
	                xtype: 'radiogroup',
	                layout: 'column',
	                allowBlank: false,
	                defaults: {
	                    name: 'distribute_snap',
	                    margins: '0 50 0 0'
	                },
	                items: [{
	                    inputValue: "110",
	                    boxLabel: '淘宝商城 '
	                }, {
	                    inputValue: "123",
	                    boxLabel: '淘宝医学店 '
	                }, {
	                    inputValue: "122",
	                    boxLabel: '淘宝经管店 '
	                }, {
	                    inputValue: "111",
	                    boxLabel: '拍拍商城 '
	                }, {
	                    inputValue: "112",
	                    boxLabel: '新浪商城  '
	                }, {
	                    inputValue: "120",
	                    boxLabel: '我有商城 '
	                }]
	            },{
			        fieldLabel: '商品名称',
			        name: 'name',
			        maxLenght : 50,
			        allowBlank: false
			    },
			    {
					fieldLabel:'状态',
	                xtype: 'radiogroup',
	                layout: 'hbox',
	                allowBlank: false,
	                defaults: {
	                    name: 'onshelf',
	                    margins: '0 50 0 0'
	                },
	                items: [{
	                    inputValue: 1,
	                    boxLabel: '上架',
	                    checked: true
	                }, {
	                    inputValue: 0,
	                    boxLabel: '下架'
	                }]
	            },
				{
			        fieldLabel: '渠道商品号',
			        name: 'distributeCommodity',
			        maxLenght : 50,
			        allowBlank: false
			    },
				{
			        fieldLabel: '价格',
			        name: 'price',
			        xtype : 'numberfield',
			        maxLenght : 50,
			        allowBlank: false
			    },
				{
			        fieldLabel: '库存',
			        name: 'stock',
			        xtype : 'numberfield',
			        maxLenght : 50,
			        allowBlank: false
			    },
				{
			        fieldLabel: '图片摘要',
			        name: 'coversdigest',
			        maxLenght : 50
			    },
				{
			        fieldLabel: '描述摘要',
			        name: 'descriptiondigest',
			        maxLenght : 50
			    },
				{
			        fieldLabel: '创建时间',
			        name: 'createtime',
			        xtype: 'datefield',
			        format: 'Y-m-d H:m:s'
			    },
				{
			        fieldLabel: '最近更新时间',
			        name: 'lastupdatetime',
			        xtype: 'datefield',
			        format: 'Y-m-d H:m:s'
			    }
			]
		});
		this.items = [this.form];
		this.buttons = [
			{text:'保存',scope:this,handler:this._save},
			{text:'取消',scope:this,handler:function(){this.hide();}}
		];
		this.callParent();
		this.on('hide',function(){this.form.form.reset();},this);
		this.on('show',function(){
			this.form.form.reset();
			var o = this.fcmp;	
			var m = o.center.getSelectionModel().getSelection();
			this.form.form.loadRecord(m[0]);
			this.form.form.findField('createtime').setValue(
					Ext.util.Format.date(new Date(parseInt(m[0].get('createtime'))),'Y-m-d H:m:s')
					);
			this.form.form.findField('createtime').setValue(
					Ext.util.Format.date(new Date(parseInt(m[0].get('createtime'))),'Y-m-d H:m:s')
					);
			this.form.form.findField('lastupdatetime').setValue(
					Ext.util.Format.date(new Date(parseInt(m[0].get('lastupdatetime'))),'Y-m-d H:m:s')
					);
			this.form.form.findField('onshelf').setValue(
					m[0].get('onshelf') ? 1 :0
					);
			this.form.form.findField('distribute_snap').setValue(
					m[0].get('commoditySnapPK.distribute')
				);
			this.form.form.findField('commodity').setValue(m[0].get('commoditySnapPK.commodity'));
			this.form.form.findField('commodity').focus(true,true);
			var dataIn = this.form.form.getValues();
		},this);
	},
	_save : function(){
		if(this.form.form.isValid()){
			var dataIn = this.form.form.getValues();
			dataIn.url = '/commoditysnap/add.json';
			dataIn.distribute = dataIn.distribute_snap;
			if(this._winType!='exclude'){
				dataIn.url = '/commoditysnap/edit.json';
			}
			channel.openLink({
				url	:dataIn.url,
				params : dataIn,
				scope : this,
				masker : this,
				onSuccess : function(rs){
					this.hide();
//					this.fcmp.west.store.load();
					this.fcmp.center.store.load();
				}
			});
		}
	}
});